// pages/card1/card1.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },
  onShow() {
    app.checkUser(app.globalData.openid, this)
  },
  getData() {
    var that = this;
    wx.request({
      url: app.globalData.host + 'index.php/api/goods/goodsInfo?admin_id=' + app.globalData.admin_id + '&type=' + 67213 + '&code=3',
      success: function (e) {
        // console.log(e)
        that.setData({
          items: e.data.result[0]
        })
        // console.log(e.data.result[0])
        var article = e.data.result[0].goods_content;
        WxParse.wxParse('article', 'html', article, that, 8);
      }
    })
  },
  tobuy() {
    var that = this;
    app.payFor(that.data.vipInfo.nickname, that.data.vipInfo.mobile, that.data.items.shop_price, "【次数卡】" + that.data.vipInfo.nickname, function () {
      wx.request({
        url: 'https://xcxu.we-fs.com/index.php/api/goods/order1',
        method: 'post',
        data: {
          'name': that.data.vipInfo.nickname,
          'sj': that.data.vipInfo.mobile,
          'goods_name': "【次数卡】" + that.data.vipInfo.nickname,
          'price': that.data.items.shop_price,
          // 'liuyan': e.currentTarget.dataset.liuyan,
          // 'dz': r.provinceName + r.cityName + r.countyName + r.detailInfo,
          'admin_id': app.globalData.admin_id,
          'goods_id': that.data.items.goods_id,
          'openid': app.globalData.openid
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res.data)
          app.showPop('购买成功', true)
          app.checkUser(app.globalData.openid, that)
          setTimeout(function () {
            that.setData({
              loadingHidden: true
            })
          }, 1500)
          
          //会员增加次数
          console.log('次数', parseInt(that.data.items.f_3))
          wx.request({
            url: 'https://xcxu.we-fs.com/index.php/api/User/userModifyVipnum',
            method:'POST',
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            data:{
              admin_id: app.globalData.admin_id,
              num: parseInt(that.data.items.f_3),
              mobileOrId: that.data.vipInfo.user_id
            },
            success:function(res){
              console.log(res,'nianka')
              if(res.data.status == 1){
                app.checkUser(app.globalData.openid, that)
              }
              else{
                wx.showToast({
                  title: res.data.msg,
                  image: 'none'
                })
              }
            }
          })

        }
      })

    })
  }


})